//----------------------------------------------------------------------------
// Filename                : pwm.c
//
// Functional Description  : PWM support functions
//----------------------------------------------------------------------------

#include "DRV922xx_trapezoidal_sensored.h"
#include "message_protocol_application.h"

/*
 *  \fn void pwm_disable()
 *  \brief Disables all 6 PWM outputs without affecting timing or synchronization
 */
void pwm_disable()
{
	// Turn all PWM signals off at Ports
    P2OUT = led;
    P2SEL = 0;
}     
void pwm_blink_led(void)
{
	led ^= 1;
	if (!led)
	{
		P2OUT &= ~0x01;
	}
	else
	{
		P2OUT |= 0x01;
	}
}

void pwm_drain_charge(void)
{
	P2OUT = 0x54 | led;
	P2SEL = 0;
}
/*
 * \fn void pwm_enable(comm_tbl_index)
 * \brief Enables PWM and sets state of P2OUT and P2SEL depending on if we are in 100% duty mode and comm state
 */
void pwm_enable(unsigned char comm_tbl_index)
{
	// See if we are in reverse drive mode
	if (reverse_drive == 0)
		comm_tbl_index += 3;
			
	P2OUT = Comm_Values[comm_tbl_index] | led;						// P2OUT (pre-driver output state [if not PWM])

	if (complementary_pwm)
		P2SEL = Comm_Values[comm_tbl_index+2];							// P2SEL (pre-driver PWM state for Complementary Mode)
	else
		P2SEL = Comm_Values[comm_tbl_index+1];							// P2SEL (pre-driver PWM state for Non-complementary Mode)
		
}   
